package com.anmong.cloud.cloudcommon.response;

import com.anmong.cloud.cloudcommon.util.PageUtils;
import lombok.Data;

import java.util.*;

@Data
public class R {
    private boolean success;
    private String code;
    private String message;
    private Collection data;
    private PageUtils page;

    public static R collection(Collection collection){
        R r = new R();
        r.setSuccess(true);
        r.setData(collection);
        r.setCode("200");
        return r;
    }

    public static R page(PageUtils page){
        R r = new R();
        r.setSuccess(true);
        r.setData(page.getList());
        r.setPage(page);
        r.setCode("200");
        return r;
    }

    public static R collectionItem(Object object){
        R r = new R();
        r.setSuccess(true);
        List list = new ArrayList();
        list.add(object);
        r.setCode("200");
        r.setData(list);
        return r;
    }

    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode("200");
        return r;
    }

    public static R error(String errorCode, String msg) {
        R r = new R();
        r.setCode(errorCode);
        r.setMessage(msg);
        return r;
    }
}
